package com.ruoyi.wxorali.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class AppUtil {

    //检测是否淘宝口令
    public static boolean istbl(String msg){
        boolean flag = false;
        if(msg.indexOf("Taobao")!=-1 || msg.indexOf("taobao")!=-1 || msg.indexOf("tmall")!=-1 || msg.indexOf("m.tb")!=-1 || msg.indexOf("tao")!=-1 || msg.indexOf("Tao")!=-1){
            flag = true;
        }else{
            //淘口令正则
            //tring tblregex = "\\$([\\s\\S]*?)\\$,&([\\s\\S]*?)&,€([\\s\\S]*?)€,￥([\\s\\S]*?)￥,¥([\\s\\S]*?)¥,£([\\s\\S]*?)£,₳([\\s\\S]*?)₳,₴([\\s\\S]*?)₴,¢([\\s\\S]*?)¢,₤([\\s\\S]*?)₤";
            String tblregex ="([/($￥€₤₳¢¤฿฿₵₡₫ƒ₲₭£₥₦₱〒₮₩₴₪៛﷼₢ℳ₰₯₠₣₧ƒ])\\w{8,12}([/)($￥€₤₳¢¤฿฿₵₡₫ƒ₲₭£₥₦₱〒₮₩₴₪៛﷼₢ℳ₰₯₠₣₧ƒ])";
            Pattern p=Pattern.compile(tblregex);
            Matcher m=p.matcher(msg);
            if(m.find()){
                flag = true;
            }
        }
        return flag;
    }

/*        public static void main(String[] args) throws IOException {
        String url = "https://u.jd.com/tIJzGHy";
            if( url.indexOf("item.jd.com")!=-1){
                String[] urlReplace = url.split(".html");
                String spnumurl = urlReplace[0];
                String regEx="[^0-9]";
                Pattern p = Pattern.compile(regEx);
                Matcher m = p.matcher(spnumurl);
                String spnum = m.replaceAll("").trim();
                System.out.println(spnum);
                url = "https://item.jd.com/"+spnum+".html";
            }
            String title = "";
            String img = "";
            String spName = "";
            List<String> skuList = new ArrayList<String>();
            Map<String,Object> jdMap = new HashMap<String,Object>();
            Document document = Jsoup.parse(new URL(url), 30000);
            Elements spa = document.getElementsByClass("name");
            Elements strong = spa.select("a");
            spName = strong.html();
            Element imgElement = document.getElementById("spec-img");
            Pattern p2 = Pattern.compile("data-origin=\"(.*?)\"");
            Matcher m2 = p2.matcher(imgElement.toString());
            while(m2.find()) {
                img = m2.group(1).trim();
            }
            Pattern p1 = Pattern.compile("alt=\"(.*?)\"");
            Matcher m1 = p1.matcher(imgElement.toString());
            while(m1.find()) {
                title = m1.group(1).trim();
            }

            Elements skuDiv = document.getElementById("choose-attrs").select("div[class~=^dd]");
            String ddsku = skuDiv.toString();
            if(StringUtils.isNotEmpty(ddsku)){
                String[] dds = ddsku.split("<div class=\"dd\">");
                if(dds.length>0){
                    String skus = dds[1];
                    Pattern p3 = Pattern.compile("data-value=\"(.*?)\"");
                    Matcher m3 = p3.matcher(skus.toString());
                    while (m3.find()) {
                        skuList.add(m3.group(1));
                    }
                }
            }
            jdMap.put("title",title);
            jdMap.put("img",img);
            jdMap.put("spName",spName);
            jdMap.put("skuList",skuList);
    }*/

}
